<template>
	<view class="com-mui-player y-flex">
		<web-view ref="webview" class="y-flex-1" src="/hybrid/html/mui-player.html"></web-view>
	</view>
</template>

<script>
	export default {
		props: {
			src: {
				type: String,
				default: ''
			},
			title: {
				type: String,
				default: ''
			},
			poster: {
				type: String,
				default: ''
			},
			autoplay: {
				type: Boolean,
				default: false
			},
			barrages: {
				type: Array,
				default: () => []
			},
			isLive: {
				type: Boolean,
				default: false
			}
		},
		mounted () {
			this.$nextTick(() => {
				if ( this.src ) this.setVideo()
			})
		},
		methods: {
			setVideo () {
				const arg = {
					src: this.src,
					poster: this.poster,
					autoplay: this.autoplay,
					barrages: this.barrages,
					isLive: this.isLive
				}
				this.$refs.webview && this.$refs.webview.evalJS(`setVideo('${encodeURIComponent(JSON.stringify(arg))}');`)
			}
		},
		watch: {
			src (newVal) {
				console.log('newVal', newVal);
				if ( newVal ) this.setVideo()
			}
		}
	}
</script>

<style>
</style>